package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.util.ShiroUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("sellerController")
public class SellerController {

    @Reference
    private SellerService sellerService;

    @RequestMapping("toRegister")
    public String toRegister(){
        return "register";
    }

    @RequestMapping("register")
    @ResponseBody
    public Result register(TbSeller tbSeller){

        String salt = ShiroUtils.generateSalt(6);
        String md5 = ShiroUtils.encryptPassword("MD5", tbSeller.getPassword(), salt, 3);

        tbSeller.setBankSeller(salt);
        tbSeller.setPassword(md5);

        boolean b = sellerService.selectSellerId(tbSeller);

        return Result.build(ConstantEnum.SUCCESS).setResult(b);
    }

}
